Ext.ns('journal.home');

// {{{
journal.home.ImportWindow = Ext.extend(Ext.Window, (function() {
    return {

        // configurables
        // anything what is here can be configured from outside

        // {{{
        initComponent : function() {

            // hard coded config - cannot be changed from outside
            var config = {
                id : 'win-import',
                layout : 'fit',
                title : 'Import Code',
                modal : true,
                resizable : false,
                constrain : true,
                maximizable : false,
                closable : true,
                items : [ new Ext.FormPanel({
                    fileUpload : true,
                    frame : true,
                    bodyStyle : 'padding: 10px 10px 0 10px;',
                    defaults : {
                        anchor : '95%',
                        allowBlank : false,
                        msgTarget : 'side'
                    },
                    items : [ {
                        xtype : 'fileuploadfield',
                        id : 'form-file',
                        emptyText : 'Select an xml file',
                        fieldLabel : 'File',
                        labelWidth : 10,
                        name : 'file-path',
                        buttonText : '',
                        buttonCfg : {
                            iconCls : 'upload-icon'
                        }
                    } ],
                    buttons : [ {
                        text : 'Submit',
                        handler : function(b) {
                            if (b.ownerCt.ownerCt.getForm().isValid()) {
                                b.ownerCt.ownerCt.getForm().submit({
                                    url : 'home?action=importCodeXml',
                                    waitMsg : 'Importing...',
                                    success : function(fp, o) {
                                        Ext.getCmp(journal.Constant.Id.ENTRY_TREE).getRootNode().reload();
                                        Ext.Msg.alert('Success', 'Successfully imported file on the server');
                                        b.ownerCt.ownerCt.ownerCt.close();
                                    }
                                });
                                b.ownerCt.ownerCt.ownerCt.hide();
                            }
                        }
                    }, {
                        text : 'Cancel',
                        handler : function(b, c) {
                            b.ownerCt.ownerCt.ownerCt.close();
                        }
                    } ]
                })

                ],
                listeners : {
                    render : function(w) {
                        w.height = 150;
                        w.width = 500;
                    }
                }
            };// var config

            // apply config
            Ext.apply(this, Ext.apply(this.initialConfig, config));

            // call parent
            journal.home.ImportWindow.superclass.initComponent.apply(this, arguments);

        } // e/o function initComponent
    // }}}
    };
})()); // e/o extend

// register xtype
Ext.reg('journal.home.ImportWindow', journal.home.ImportWindow);
// }}}
